<?php
use PHPLog\Install_File;
use PHPLog\Install\Common;
require_once "Common/CommonFunctions.php";
require_once "Common/cQueryString.php";

$str_CodeInfo = Common\clean_Path(dirname(dirname(dirname(__FILE__))) . "\\Code\\cCodeInfo.php");

$str_History = Common\clean_Path(dirname(dirname(dirname(dirname(__FILE__)))) . "\\PHP_Updater\\code\\Classes\\History\\cHistory.php");
$str_Version = Common\clean_Path(dirname(dirname(dirname(dirname(__FILE__)))) . "\\PHP_Updater\\code\\Classes\\cVersion.php");

require_once $str_CodeInfo;
require_once $str_History;
require_once $str_Version;

if (@$_POST[Common\cQueryString::C_STR_PHP_LOG_PATH])
{
	$GLOBALS ["PATH_CODE"] = $_REQUEST [Common\cQueryString::C_STR_PHP_LOG_PATH];
}
else
{
	$GLOBALS ["PATH_CODE"] = Install_File\cCodeInfo::C_STR_CODE;
}

if (@$_POST [Common\cQueryString::C_STR_PHP_UPDATER_PATH])
{
	$GLOBALS ["C_STR_PATH2UPDATER"] = $_REQUEST [Common\cQueryString::C_STR_PHP_UPDATER_PATH];
}
else
{
	$GLOBALS ["C_STR_PATH2UPDATER"] = Install_File\cCodeInfo::C_STR_PATH2UPDATER;
}

$str_History_Path = Common\clean_Path($GLOBALS ["PATH_CODE"] . "/Setup/Install_History.xml");

Common\open_History($str_History_Path);

$GLOBALS ["Install_History_File"]->set_UpdateURL("http://do-php-logging.googlecode.com/files/Updates.xml");

create_Dir();

$obj_Version = new PHPUpdater\cVersion(0, 1, 0);
$GLOBALS ["Install_History_File"]->set_Version($obj_Version);

Common\save_History();

?>

<html>
<head>
<title>Install PHP Log</title>

<script type="text/javascript" src='Common/JS/CommonFunctions.js'></script>

<script language="javascript" type="text/javascript">
<!-- 
function do_Config()
{
	var m_obj_AJAX = get_Ajax();
	
	var arr_Params = new Array();
	var str_Params = "";
	
	arr_Params["C_STR_CODE"] 			= "<?php
	print($GLOBALS ["PATH_CODE"]);
	?>";
	arr_Params["C_STR_PATH2UPDATER"] 	= "<?php
	print($GLOBALS ["C_STR_PATH2UPDATER"]);
	?>";
	
	str_Params = create_ParamString(arr_Params);
	
	m_obj_AJAX.open("POST", "AJAX/setup_Config.php", true);

	// Send the proper header information along with the request
	m_obj_AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	m_obj_AJAX.setRequestHeader("Content-length", str_Params.length);
	m_obj_AJAX.setRequestHeader("Connection", "close");

	m_obj_AJAX.onreadystatechange = function() 
	{// Call a function when the state changes.
		if(m_obj_AJAX.readyState == 4 && m_obj_AJAX.status == 200) 
		{
			document.getElementById('output_Config').innerHTML = m_obj_AJAX.responseText;
		}
	}
	m_obj_AJAX.send(str_Params);

}

function do_LogCopy()
{
	var m_obj_AJAX = get_Ajax();
	
	var arr_Params = new Array();
	var str_Params = "";
	
	arr_Params["C_STR_CODE"] 			= "<?php
	print($GLOBALS ["PATH_CODE"]);
	?>";
	
	
	str_Params = create_ParamString(arr_Params);
	
	m_obj_AJAX.open("POST", "AJAX/setup_Log.php", true);

	// Send the proper header information along with the request
	m_obj_AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	m_obj_AJAX.setRequestHeader("Content-length", str_Params.length);
	m_obj_AJAX.setRequestHeader("Connection", "close");

	m_obj_AJAX.onreadystatechange = function() 
	{// Call a function when the state changes.
		if(m_obj_AJAX.readyState == 4 && m_obj_AJAX.status == 200) 
		{
			document.getElementById('output_Log').innerHTML = m_obj_AJAX.responseText;
		}
	}
	m_obj_AJAX.send(str_Params);

}

do_Config();
do_LogCopy();

// -->
</script>
</head>
<body>
<h1>Install PHP Log</h1>
<div ID="output_Config">Wait...</div>
<div ID="output_Log">Wait...</div>
</body>
</html>

<?php

function create_Dir()
{
	Common\create_Directory(Common\clean_Path($GLOBALS ["PATH_CODE"] . "/Setup"));
}

?>

